import Vue from 'vue';
import Vuex from 'vuex'
import axios from "axios";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

Vue.use(Vuex);


export default new Vuex.Store({
	state:{
		list:[],
		addEdit:''

	},
	mutations:{
		//table  列表  数据
		initList(state,list){
			state.list=list;
		},
		// 添加编辑数据
		addEdit(state,newData){
			state.addEdit=newData;
		}		 	
	},
	actions:{
		 async getlist(cont,params){ 
	      await axios({
	            method: "get",
	            url:params.url,
	            params:params.param,
	            headers: {
	                "Content-Type": "application/json;charset=UTF-8"
	            }
	        }).then(res => {   				  
				  if(res.data.code==0){
					cont.commit('initList',res.data.data); //调用 mutations  方法
				  }else{					 
					  ElementUI.Message ({
						title: '警告',
						message: res.data.msg,
						type: 'warning'
					});     
				  }								
				        
	        }).catch(error=>{	
				ElementUI.Message ({
					title: '警告',
					message: res.data.msg,
					type: 'error'
				});  			
	        }); 
	    },
	     async postform(cont,params){ 			   
    		await axios({
                method: "post",
                url: params.url,
                data: params.param,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8"
                }
            }).then(res=> { 
                cont.commit('addEdit',res.data) //调用 mutations  方法                                                            
            })
            .catch(error=>{
             	cont.commit('addEdit',res.data) //调用 mutations  方法  
            });              
	    }
	   
	    		

	},
	getters:{

	}

   
 })
